package com.kevinxiaoge.ruoli.demo;

/**
 * 懒汉式
 *
 * @author chengyuanyuan
 */
public class LazyMan {

    public volatile static LazyMan LAZY_MAN;

    private LazyMan(){}

    public static LazyMan getInstance() {
        if (LAZY_MAN == null) {
            synchronized (LazyMan.class) {
                if (LAZY_MAN == null) {
                    LAZY_MAN = new LazyMan();
                }
            }
        }
        return LAZY_MAN;
    }
}

class LazyManTest {
    public static void main(String[] args) {
        LazyMan instance = LazyMan.getInstance();
        LazyMan instance1 = LazyMan.getInstance();
        System.out.println(instance == instance1);
    }
}
